#pragma once
#include<iostream>
#include<pthread.h>

//这里要自动进行加锁和解锁的操作
class Mutex
{
public:
    Mutex(pthread_mutex_t* mutex)
    :_mutex(mutex)
    {}
    void lock()
    {
        std::cout<<"要进行加锁"<<std::endl;
        pthread_mutex_lock(_mutex);
    }
    void unlock()
    {
        std::cout<<"要进行解锁"<<std::endl;
        pthread_mutex_unlock(_mutex);
    }
    ~Mutex(){

    }
private:
    pthread_mutex_t *_mutex;
};
class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mutex)
    :_mtx(mutex)
    {
        _mtx.lock();
    }
    ~LockGuard(){
        _mtx.unlock();
    }
private:
    Mutex _mtx;
};